<%@ page import="java.io.StringWriter" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isErrorPage="true" %>
<!DOCTYPE html>
<html>
<head>
  <title>出错啦 - 教务管理系统</title>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
      font-family: 'Microsoft YaHei', sans-serif;
    }
    body {
      background: #f5f7fa;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
      color: #2c3e50;
    }
    .error-container {
      text-align: center;
      padding: 40px;
      background: white;
      border-radius: 12px;
      box-shadow: 0 10px 30px rgba(0,0,0,0.1);
      max-width: 600px;
      width: 90%;
    }
    .error-icon {
      font-size: 80px;
      color: #e74c3c;
      margin-bottom: 20px;
    }
    h1 {
      margin-bottom: 15px;
      font-size: 28px;
    }
    .error-message {
      margin: 20px 0;
      padding: 15px;
      background: #fef2f2;
      border-radius: 8px;
      color: #dc2626;
      word-break: break-word;
    }
    .action-btn {
      display: inline-block;
      margin-top: 25px;
      padding: 12px 25px;
      background: #3498db;
      color: white;
      text-decoration: none;
      border-radius: 6px;
      transition: all 0.3s;
    }
    .action-btn:hover {
      background: #2980b9;
      transform: translateY(-2px);
    }
    .error-details {
      margin-top: 30px;
      font-size: 14px;
      color: #7f8c8d;
      border-top: 1px dashed #eee;
      padding-top: 20px;
    }
    .stack-trace {
      margin-top: 30px;
      text-align: left;
      max-height: 300px;
      overflow-y: auto;
      background: #2c3e50;
      color: #ecf0f1;
      padding: 15px;
      border-radius: 6px;
      font-family: monospace;
      font-size: 13px;
    }
  </style>
</head>
<body>
<div class="error-container">
  <div class="error-icon">❌</div>
  <h1>糟糕，出错了！</h1>
  <p>我们遇到了问题处理您的请求</p>

  <div class="error-message">
    <% if (exception != null) { %>
    <%= exception.getMessage() %>
    <% } else { %>
    服务器内部错误（错误代码：<%= request.getAttribute("javax.servlet.error.status_code") %>）
    <% } %>
  </div>

  <div>
    <a href="${pageContext.request.contextPath}/" class="action-btn">
      返回首页
    </a>
    <a href="javascript:history.back()" class="action-btn" style="background: #95a5a6; margin-left: 10px;">
      返回上一页
    </a>
  </div>

  <div class="error-details">
    <p>如需帮助，请联系管理员并提供以下信息：</p>
    <p>时间：<%= new java.util.Date() %></p>
    <p>路径：<%= request.getAttribute("javax.servlet.error.request_uri") %></p>
  </div>
  <% if (exception != null && "true".equals(request.getParameter("debug"))) { %>
  <div class="stack-trace">
    <%
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      exception.printStackTrace(pw);
      System.out.print(sw.toString().replace("\n", "<br>"));
    %>
  </div>
  <% } %>
</div>
</body>
</html>
